import Router from 'vue-router'
import Layout from '@/layout'
// 引入路由表
import taotuRouter from './taotuRouter'
import guixiuRouter from './guixiuRouter'
import sehuluRouter from "./sehuluRouter";
import xofuliRouter from "./xofuliRouter";
import meituluRouter from "./meituluRouter";

export const constantRouterMap = [{
  path: '/',
  component: Layout,
  redirect: '/taotuList',
  hidden: true,
  children: [{
    path: '/taotuList',
    component: () => import('@/views/pages/taotu/taotuList'),
    hidden: true
  },],
}, {
  path: '/login',
  component: () => import('@/views/login'),
  hidden: true
}, {
  path: '*',
  component: () => import('@/views/error-page/404'),
  hidden: true
}]

// 合并异步路由
export const asyncRoutes = [
  ...taotuRouter,
  ...guixiuRouter,
  ...sehuluRouter,
  ...xofuliRouter,
  ...meituluRouter,
]

const createRouter = () => new Router({
  scrollBehavior: () => ({y: 0}),
  routes: constantRouterMap, // 确保合并常量和异步
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export function selfaddRoutes(params) {
  router.matcher = new Router().matcher
  router.addRoutes(params)
}

export default router
